<template>
  <div :class="[isShow ? 'cart-submit-bar' : '']">
    <van-submit-bar :price="amount" button-text="去结算" :disabled="!canSubmit" class="submit-bar" @submit="onSubmit">
      <van-checkbox v-show="showCheckAll" v-model="checked" icon-size="18px" :checked-color="variables.theme">全选</van-checkbox>
      <template #button>
        <div v-if="normalProduct">
          <van-button round color="linear-gradient(to right, #ff6034, #ee0a24)" @click="onSubmit">去结算</van-button>
        </div>
        <div v-if="!slotName">
          <!-- <van-button v-if="isCheckPurchase" :disabled="!timeFlag" class="mr-18" round type="info"
            color="linear-gradient(to right, #ff6034, #ee0a24)" @click="addShelves">去上架</van-button> -->
          <!--          <van-button @click="onSubmit" round type="info" color="linear-gradient(to right, #ff6034, #ee0a24)">去结算</van-button>-->
          <!-- <van-button v-if="isCheckPurchase && checkTarget.saleStatus === 0" @click="onConfirm" round
            color="linear-gradient(to right, #ff6034, #ee0a24)">去确认</van-button> -->
          <van-button
            v-if="isCheckPurchase && checkTarget.saleStatus === 1"
            round
            color="linear-gradient(to right, #ff6034, #ee0a24)"
            @click="onConfirm('pay')"
          >去付款</van-button>
        </div>
        <slot v-else />
      </template>

      <slot name="warehouse" />
    </van-submit-bar>
    <div class="submit-bar-placeholder" style="width: 100%; height: 50px" />
  </div>
</template>

<script>
import variables from '@/styles/variables.scss'

export default {
  props: {
    amount: {
      type: Number,
      default: 0
    },
    value: {
      type: Boolean,
      default: false
    },
    isShow: {
      type: Boolean,
      default: () => false
    },
    isCheckPurchase: {
      type: Boolean,
      default: () => false
    },
    timeFlag: {
      type: Boolean,
      default: () => false
    },
    slotName: {
      type: String,
      default: () => ''
    },
    checkTarget: {
      type: Object
    },
    normalProduct: {
      type: Boolean,
      default: () => false
    },
    showCheckAll: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      disabled: false,
      allchecked: this.value
    }
  },
  computed: {
    variables() {
      return variables
    },
    checked: {
      get() {
        return this.allchecked
      },
      set(val) {
        this.allchecked = val
        this.$emit('input', val)
      }
    },
    canSubmit() {
      return this.amount > 0
    }
  },
  methods: {
    onSubmit() {
      if (this.isCheckPurchase) {
        this.$emit('settle')
        return
      }
      console.log('checkTarget===',this.checkTarget)
      if (this.amount <= 0) {
        return this.$toast.success('请至少选择一件商品')
      }
      this.$emit('onSubmit')
    },
    addShelves() {
      this.$emit('add')
    },
    onConfirm(type) {
      this.$emit('confirm', type)
    }
  }
}
</script>

<style>
:root {
  --submit-bar-shadow: 0px -2px 10px 0px rgba(0, 0, 0, 0.08);
}
</style>

<style scoped>
.submit-bar {
  /* 这里使用 css 函数，是为了避免旧版本 vue-cli 依赖的 css 压缩工具（mini-css-extract-plugin）导致的 bug */
  box-shadow: var(--submit-bar-shadow);
}

.van-submit-bar {
  bottom: 100px;
}
</style>

<style scoped lang="scss">
.cart-submit-bar {
  //::v-deep .van-submit-bar__text {
  //  span {
  //    display: none;
  //  }
  //}
}

.mr-18 {
  margin-right: 18px;
}
</style>
